package com.chen.admin.service;


import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chen.admin.common.Result;
import com.chen.admin.entity.HotelRoom;
import com.chen.admin.mapper.HotelRoomMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HotelRoomService {


    @Autowired
    private HotelRoomMapper hotelRoomMapper;

//    public Page<HotelRoom> hotelRoomGetPageList(Integer pageNumber,Integer pageSize) {
//       Page<HotelRoom> hotelRooms = hotelRoomMapper.selectPage(new Page<>(pageNumber, pageSize), new LambdaQueryWrapper<>());
//        return hotelRooms;
//    }

        public List<HotelRoom> hotelRoomGetPageList() {
            List<HotelRoom> hotelRoomList = hotelRoomMapper.selectInfoPage();
            return hotelRoomList;
    }



    public Result hotelRoomAdd(HotelRoom hotelRoom) {
        int hasWindowValue = hotelRoom.getHasWindow()? 1 : 0;
        int breakfastValue = hotelRoom.getBreakfast()? 1 : 0;


        int count = hotelRoomMapper.hotelRoomAdd(hotelRoom,hasWindowValue,breakfastValue);
        if (count==0){
            return Result.error( "400","添加失败");
        }
        return Result.success("添加成功");
    }

    public Result updateHotelRoom(HotelRoom hotelRoom) {
        int count = hotelRoomMapper.updateById(hotelRoom);
        if (count==0){
            return Result.error( "400","修改失败");
        }
        return Result.success("修改成功");



    }

    public Result deleteHotelRoom(Integer id) {
        int count = hotelRoomMapper.deleteById(id);
        if(count==0){
            return Result.error("400","删除失败!");
        }
        return Result.success("删除成功！");
    }

    public Result deleteHotelRoomsByIds(List<Integer> ids) {

        int count = hotelRoomMapper.deleteBatchIds(ids);
        if(count==0){
            return Result.error("400","删除失败");
        }
        return  Result.success("批量删除成功");

    }

    public Result<HotelRoom> getHotelRoomByName(String roomName) {

        HotelRoom hotelRoom = hotelRoomMapper.selectOne(new LambdaQueryWrapper<HotelRoom>().eq(HotelRoom::getRoomName, roomName));
        if(ObjectUtil.isNull(hotelRoom)){
            return Result.error("400","没有此房间");
        }
        return Result.success(hotelRoom);

    }
}
